<template>
  <div>
    <div class="title">
      <el-menu
        :default-active="activeIndex"
        class="el-menu-demo"
        mode="horizontal"
        @select="stateBtn"
      >
        <el-menu-item index="0">所有订单</el-menu-item>
        <el-menu-item index="1">待付款</el-menu-item>
        <el-menu-item index="2">待发货</el-menu-item>
        <el-menu-item index="3">待收货</el-menu-item>
        <el-menu-item index="4">待归回</el-menu-item>
        <el-menu-item index="5">归还中</el-menu-item>
        <el-menu-item index="6">交易完成</el-menu-item>
        <el-menu-item index="7">已撤销</el-menu-item>
        <el-menu-item index="8">已退款</el-menu-item>
      </el-menu>
      <div>
        <!-- <el-button type="primary"><i class="el-icon-download"></i>导出</el-button> -->
        <!-- <el-button icon="el-icon-refresh" @click="refresh"></el-button> -->
      </div>
    </div>
    <div class="container">
      <div class="screeningBox">
        <div class="leftBox">
           <div class="leftitem">
              <div class="block">
              <el-date-picker
                v-model="conditions.date"
                type="datetimerange"
                value-format="yyyy-MM-dd HH:mm:ss"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['00:00:00', '23:59:59']"
              ></el-date-picker>
            </div>
          </div>
          <div class="leftitem">
            <el-form ref="conditions" :model="conditions" label-width="80px">
              <el-input class="merchants" v-model.trim="conditions.rentNo" placeholder="订单号"></el-input>
            </el-form>
          </div>
          <div class="leftitem">
            <el-form ref="conditions" :model="conditions" label-width="80px">
              <el-input class="merchants" v-model.trim="conditions.goodName" placeholder="商品名称"></el-input>
            </el-form>
          </div>
        </div>
        <div class="rightBox">
         <div class="rightitem">
            <el-form ref="conditions" :model="conditions" label-width="80px">
              <el-input class="merchants" v-model.trim="conditions.mobile" placeholder="收货人手机号"></el-input>
            </el-form>
          </div>
          <div class="rightitem">
            <el-button icon="el-icon-search" type="primary" @click="soso">搜索</el-button>
            <el-button icon="el-icon-refresh" type="primary" @click="reset">重置</el-button>
          </div>
        </div>
      </div>
      <div class="tableBox">
        <el-table
          ref="multipleTable"
          :data="merchantarr"
          tooltip-effect="dark"
          style="width: 100%"
          @selection-change="handleSelectionChange"
          stripe
          :header-cell-style="tableHeaderColor"
        >
          <el-table-column prop="createTime" align="center" label="生成时间"></el-table-column>
          <el-table-column prop="merchantName" align="center" label="商户"></el-table-column>
          <el-table-column prop="goodName" align="center" label="商品名称"></el-table-column>
          <el-table-column prop="totalRental" align="center" label="总租金">
            <template slot-scope="scope">
                <div>￥{{scope.row.totalRental}}</div>
                
            </template>
          </el-table-column>
          <el-table-column prop="deposit" align="center" label="押金">
            <template slot-scope="scope">
                <div>￥{{scope.row.deposit}}</div>
                
            </template>
          </el-table-column>
          <!-- <el-table-column prop="merchantShortName" align="center" label="其他">
            <template slot-scope="scope">
              <div>数量:X{{scope.row.pcs}}</div>
             
            </template>
          </el-table-column> -->
          <el-table-column prop="merchantName" align="center" label="租期">
            <template slot-scope="scope">
              <div>{{scope.row.startDate}}</div>
              <div>{{scope.row.endDate}}</div>
              <div>共{{scope.row.rentDays}}天</div>
            </template>
          </el-table-column>
          <el-table-column prop="actualPaid" align="center" label="实付款">
            <template slot-scope="scope">
                <div>￥{{scope.row.actualPaid/100}}</div>
                
            </template>
          </el-table-column>
          <el-table-column width="200" prop="rentNo" align="center" label="订单号"></el-table-column>
         
          <el-table-column align="center" label="交易状态">
            <template slot-scope="scope">
              <div v-if='scope.row.status == 1'>待付款</div>
              <div v-else-if='scope.row.status == 2'>待发货</div>
              <div v-else-if='scope.row.status == 3'>待收货</div>
              <div v-else-if='scope.row.status == 4'>待归还</div>
              <div v-else-if='scope.row.status == 5'>.归还中</div>
              <div v-else-if='scope.row.status == 6'>交易完成</div>
              <div v-else-if='scope.row.status == 7'>撤销</div>
              <div v-else-if='scope.row.status == 8'>已退款</div>
            </template>
          </el-table-column>
          <el-table-column align="center" label="用户地址电话">
            <template slot-scope="scope">
              <div>{{scope.row.address}}</div>
              <div>{{scope.row.mobile}}</div>
            </template>
          </el-table-column>
           <el-table-column  align="center" label="操作" fixed="right">
            <template slot-scope="scope">
                <el-button v-if="scope.row.status == 2" type="text" size="small" @click="unFreeze(scope.row.id)">撤销订单</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="pagination">
          <el-pagination
            @current-change="handleCurrentChange"
            @size-change="sizechange"
            :page-size="10"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
          ></el-pagination>
        </div>
      </div>
      <br>
      <br>
    </div>
  </div>
</template>

<script>
import { rentpage,unFreeze } from "@/api/api";
export default {
  // name: "baseform",
  data: function() {
    return {
      activeIndex: '0',
      cur_page: 1,
      cur_size: 10,
      multipleSelection: [],
      merchantarr: [],
      pageCount: "",
      total:10,
      userinfo:{},
      merchantsstate: "",
      conditions: {
        date:"",
        rentNo:"",
        goodName:"",
        mobile:""
      },
    };
  },
  created() {
    this.userinfo = JSON.parse(sessionStorage.getItem("userInfo"));
    this.merchantlist();
   
   

  },
  mounted() {},
  methods: {
    //修改thead 背景色
     tableHeaderColor({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 0) {
        return 'background-color: #F0F0F0;font-weight: 500;'
      }
    },
    // 分页导航
    handleCurrentChange(val) {
      this.cur_page = val;
      this.merchantlist();
      this.$nextTick(() => {
        document.querySelectorAll(".content")[0].scrollTop = "0";
      });
    },
    // 分页数量
    sizechange(val) {
      this.cur_size = val;
      this.merchantlist();

      this.$nextTick(() => {
        document.querySelectorAll(".content")[0].scrollTop = "0";
      });
    },

    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    joinmerchantsinfo(val) {
      this.$router.push({ path: "/auditdetails"  });
      sessionStorage.setItem('auditinfo',JSON.stringify(val))
    },
     // 商户列表
    merchantlist() {
     console.log(this.conditions)
      rentpage({
          page: this.cur_page,
          size: this.cur_size,
          merchantId: this.userinfo.fid,
          status: this.merchantsstate,
          startDate: this.conditions.date[0],
          endDate: this.conditions.date[1],
          rentNo: this.conditions.rentNo,
          goodName: this.conditions.goodName,
          mobile: this.conditions.mobile
      }).then(res => {
        console.log(res);
        if (res.code == 405) {
          sessionStorage.removeItem("token");
          this.$router.push("/login");
        } else {
            this.merchantarr = res.data
            this.total = res.pageInfo.recordCount
            this.pageCount = res.pageInfo.pageCount
        }
      });
    },
    // 搜索
    soso() {
      if(this.conditions.date == null || this.conditions.date.length == 0 || this.conditions.date == undefined) {
        this.conditions.date = []
      }
        this.merchantlist();
    },
    // 重置
    reset() {
      this.conditions =  {
        date:"",
        rentNo:"",
        goodName:"",
        mobile:"",
        cur_page: 1,
        cur_size: 10,
      }
    },
    // 刷新
    refresh() {
      // location.reload()
      this.$router.go({
        path: 0,
        query: {
          t: Date.now()
        }
      })
    },
  
  
    // 状态btn
    stateBtn(val){
      console.log(val)
      this.merchantsstate = val
      this.cur_page = 1;
      this.total = 1;
      this.reset()
      this.merchantlist()
    },
  
    // 跳详情
     addmerdetails(val) {
      this.$router.push({ path: "/addmerdetails"  });
      sessionStorage.setItem('auditinfo',JSON.stringify(val))
    },
    // 撤销订单
    unFreeze(id){

      this.$confirm('是否确定撤销？如确定，该订单将被撤销', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          unFreeze({},id).then(res => {
            console.log(res);
            if (res.code == 405) {
              sessionStorage.removeItem("token");
              this.$router.push("/login");
            } else {
                if(res.code == 200){
                  this.$message({
                        message: "撤销成功",
                        type: "success"
                    });
                    this.merchantlist()
                }else{
                  this.$message.error(res.message);
                  this.merchantlist()
                }

            }
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          });          
        });

     
    }
  }
};
</script>
<style scoped lang="less">
.title {
  background: #fff;
  padding: 10px 10px;
  font-size: 18px;
  font-weight: 500;
  display: flex;
  justify-content: space-between;
}
.name {
  width: 25%;
}
.screeningBox {
  width: 100%;
  display: flex;
}
.leftBox,
.rightBox {
  width: 50%;
  padding: 0 15px;
  box-sizing: border-box;
}
.leftBox > .leftitem {
  margin-bottom: 15px;
}
.rightBox > .rightitem {
  margin-bottom: 15px;
}
.merchants {
  width: 50%;
}
.statistical {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #00152a;
  color: #fff;
  padding: 12px;
  box-sizing: border-box;
}
.statistical > .statisticalitem {
  width: 50%;
  text-align: center;
  line-height: 200%;
}
.tableBox {
  margin-top: 20px;
}

.red {
  color: #f9607d;
}

.my-autocomplete {
  li {
    line-height: normal;
    padding: 7px;

    .name {
      text-overflow: ellipsis;
      overflow: hidden;
    }
    .addr {
      font-size: 12px;
      color: #b4b4b4;
    }

    .highlighted .addr {
      color: #ddd;
    }
  }
}
.green{
  color:green;
}
</style>